<?php

namespace Project\ScrumBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Project\ScrumBundle\Classe\StatsEnum;

class ValidationType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $id = $options['attr'];
        $builder
                ->add('refUserstorie', 'entity', array(
                    'class' => 'Project\ScrumBundle\Entity\Userstories',
                    'property' => 'role',
                    'label' => 'User story : ',
                    'query_builder' => function (\Doctrine\ORM\EntityRepository $er) use ($id) {
                        return $er->createQueryBuilder('userstory')
                                ->where('userstory.refClient = :param')
                                ->andWhere('userstory.statut = :state')
                                ->setParameters(array('param' => $id, 'state' => StatsEnum::FINI));
                    },
                ))
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'data_class' => 'Project\ScrumBundle\Entity\Affectation'
        ));
    }

    public function getName() {
        return 'project_scrumbundle_affectationtype';
    }

}
